package com.company.project.controller.ldjsc.zbgxrq;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.company.project.entity.ldjsc.wzsj.JscwzTemplateExplainEntity;
import com.company.project.entity.ldjsc.zbgxrq.TbTemplateEntity;
import com.company.project.service.ldjsc.zbgxrq.TbTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.company.project.common.utils.DataResult;





/**
 * 模板表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-08-21 08:54:03
 */
@Controller
@RequestMapping("/sxzy")
public class TbTemplateController {
    @Autowired
    private TbTemplateService tbTemplateService;

    @ApiOperation(value = "指标更新日期-列表")
    @GetMapping("/jsc-dd-zt/JscTemplate12")
    @ResponseBody
    public DataResult JscTemplate12(TbTemplateEntity tbTemplate){
        LambdaQueryWrapper<TbTemplateEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TbTemplateEntity::getName, tbTemplate.getName());
        queryWrapper.orderByDesc(TbTemplateEntity::getUpdate_time);

        if (tbTemplate.getMidgard_offset() != null){
            tbTemplate.setMidgard_page(1);
        }
        IPage<TbTemplateEntity> iPage = tbTemplateService.page(tbTemplate.getQueryPage(), queryWrapper);
        List<TbTemplateEntity> records = iPage.getRecords();


        // 构造所需的数据结构
        List<String> columnNames = Arrays.asList(
                "source",
                "name",
                "tb_delay",
                "tb_deadline",
                "tb_cycle"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }


    @ApiOperation(value = "指标更新日期-详情")
    @GetMapping("/jsc-dd-zt/JscTemplate2")
    @ResponseBody
    public DataResult JscTemplate2(TbTemplateEntity tbTemplate){
        LambdaQueryWrapper<TbTemplateEntity> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TbTemplateEntity::getName, tbTemplate.getName());
        queryWrapper.eq(TbTemplateEntity::getSource, tbTemplate.getSource());
        queryWrapper.orderByDesc(TbTemplateEntity::getUpdate_time);

        if (tbTemplate.getMidgard_offset() != null){
            tbTemplate.setMidgard_page(1);
        }
        IPage<TbTemplateEntity> iPage = tbTemplateService.page(tbTemplate.getQueryPage(), queryWrapper);
        List<TbTemplateEntity> records = iPage.getRecords();


        // 构造所需的数据结构
        List<String> columnNames = Arrays.asList(
                "source",
                "name",
                "tb_delay",
                "tb_deadline",
                "tb_cycle"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }


    @ApiOperation(value = "指标更新日期-列表1")
    @GetMapping("/jsc-dd-zt/JscTemplateLb2")
    @ResponseBody
    public DataResult JscTemplateLb2(TbTemplateEntity tbTemplate){
        String name =tbTemplate.getName();
        List<TbTemplateEntity> records = tbTemplateService.selectByName(name);

        List<String> columnNames = Arrays.asList(
                "source",
                "name",
                "tb_delay",
                "tb_deadline",
                "tb_cycle"
        );

        Map<String, Object> result = new HashMap<>();
        result.put("columnNames", columnNames);
        result.put("value", records);

        return DataResult.success(result);
    }
}
